package com.financing.platform.web;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.financing.platform.dto.SwitchDTO;
import com.financing.platform.service.ISwitchService;
import com.financing.platform.util.DTOdateSet;
import com.financing.platform.util.Dict;

@Controller
public class SwitchAction extends BaseAction{
	
	@Autowired
	ISwitchService switchSerivceImpl;
	
	@RequestMapping("/querySwitch.shtml")
	public ModelAndView querySwitch(HttpServletRequest request,
			HttpServletResponse response) {
			request.getSession().setAttribute(Dict.requestID, "querySwitch.shtml");
			List<SwitchDTO> switchList = switchSerivceImpl.queryAllSwitch();
			Map<String,Object> resultMap = new HashMap<String,Object>();
			resultMap.put("switchList", switchList);
			return new ModelAndView("switchList",resultMap);
	}
	
	@RequestMapping("/updateSwitch.shtml")
	public ModelAndView updateSwitch(HttpServletRequest request,
			HttpServletResponse response,SwitchDTO switchDto) {
			DTOdateSet.setUpdateInfo(switchDto, request.getSession());
			Map<String,Object> resultMap = new HashMap<String,Object>();
			if(Dict.switchOff.equals(switchDto.getsValue())|| Dict.switchOn.equals(switchDto.getsValue())){
				resultMap.put("result",  switchSerivceImpl.updateSwitch(switchDto));
			}else{
				resultMap.put("result", 0);
			}
			return new ModelAndView("updateSwitchResult",resultMap);
	}
}
